@extends('admin.layouts')
@section('main')
    <div class="container-fluid larry-wrapper">
        <div class="row">
            <div class="col-xs-12 col-sm-12 col-md-12">
                <!--列表-->
                <section class="panel panel-padding">
                    <div class="group-button">
                        <button class="layui-btn layui-btn-small layui-btn-danger ajax-all" data-name="id" data-params='{"url": "{{url('admin/userdel')}}","method":"post","data":"_token={{csrf_token()}}","confirm":"true","confirmTest":{"title":"{{trans('config.message')}}","msg":"{{trans('config.btn_text_delete')}}","btn":["{{trans('config.yes')}}","{{trans('config.no')}}"]} }'>
                            <i class="iconfont">&#xe626;</i> {{trans('config.btn_delete')}}
                        </button>
                        <button id="add" class="layui-btn layui-btn-small modal-catch" data-params='{"content":".add-subcat","area":"600px,auto", "title":"{{trans('config.add_user')}}","type":"1","shadeClose":1}'>
                            <i class="iconfont">&#xe649;</i> {{trans('config.btn_add')}}
                        </button>
                    </div>
                    <div id="list" class="layui-form"></div>

                    <div class="text-right" id="page"></div>
                </section>
            </div>
        </div>
    </div>

    <div class="add-subcat">
        <form id="form1" class="layui-form layui-form-pane" action="{{url('admin/useradd')}}">
            {{csrf_field()}}
            <input type="hidden" name="id" value="">
            <div class="layui-form-item">
                <label class="layui-form-label">{{trans('config.user')}}</label>
                <div class="layui-input-inline">
                    <input type="text" name="name" required jq-verify="required" jq-error="{{trans('config.vali_required')}}" placeholder="{{trans('config.input_name')}}" autocomplete="off" class="layui-input ">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">{{trans('config.password')}}</label>
                <div class="layui-input-inline">
                    <input type="password" name="password" placeholder="{{trans('config.input_password')}}" jq-verify="required|password" jq-error="{{trans('config.vali_required')}}|{{trans('config.vali_password')}}" autocomplete="off" class="layui-input ">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">{{trans('config.email')}}</label>
                <div class="layui-input-inline">
                    <input type="text" name="email" placeholder="{{trans('config.input_email')}}" jq-verify="required|email" jq-error="{{trans('config.vali_required')}}|{{trans('config.vali_email')}}" autocomplete="off" class="layui-input ">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" jq-submit jq-filter="submit">{{trans('config.btn_submit')}}</button>
                </div>
            </div>
        </form>
    </div>
@endsection

@section('script')

<script id="list-tpl" type="text/html" data-params='{"url":"{{url('admin/userlist')}}","method":"post","data":{"_token":"{{csrf_token()}}"},"pageid":"#page"}'>
    <table id="example" class="layui-table lay-even">
        <thead>
        <tr>
            <th width="30"><input type="checkbox" id="checkall" data-name="id" lay-filter="check" lay-skin="primary"></th>
            <th width="60">ID</th>
            <th>用户名</th>
            <th>邮箱</th>
            <th width="80">状态</th>
            <th width="200">操作</th>
        </tr>
        </thead>
        <{# layui.each(d.list, function(index, item){ }>
        <tr>
            <td><input type="checkbox" name="id" value="<{item.id}>" lay-skin="primary"></td>
            <td><{item.id}></td>
            <td><{item.name}></td>
            <td><{item.email}></td>
            <td><input type="checkbox" name="status" value="<{item.status}>" <{# if(item.status==1){ }>checked<{# } }> lay-skin="switch" lay-text="{{trans('config.btn_enable')}}|{{trans('config.btn_disable')}}" lay-filter="ajax" data-params='{"url":"{{url('admin/useredit')}}","data":"id=<{item.id}>&_token={{csrf_token()}}" }'> </td>
            <td>
                <button class="layui-btn layui-btn-mini layui-btn-normal modal-iframe" data-params='{"content": "{{url('admin/usereditrole')}}?id=<{item.id}>","title": "{{trans('config.config_user')}}","full":"true"}'>
                    <i class="layui-icon">&#x1005;</i>{{trans('config.btn_role')}}
                </button>
                <button class="layui-btn layui-btn-mini modal-catch luck-edit" data-params='{"content": ".add-subcat","title": "{{trans('config.edit_user')}}","type":"1","area":"600px,auto","shadeClose":1}' data-name="<{item.name}>" data-email="<{item.email}>" data-id="<{item.id}>">
                    <i class="iconfont">&#xe653;</i>{{trans('config.btn_edit')}}
                </button>
                <button class="layui-btn layui-btn-mini layui-btn-danger" data-method="del" data-url="{{url('admin/userdel')}}" data-id="<{item.id}>">
                    <i class="iconfont">&#xe626;</i>{{trans('config.btn_delete')}}
                </button></td>
            </td>
        </tr>
        <{# }); }>
        </tbody>

    </table>
</script>


<script>
    layui.use(['list','jquery'],function() {
        var $ = layui.jquery;
        $("#add").click(function(){
            $('input[name=id]').val('');
            $('input[name=name]').val('');
            $('input[name=email]').val('');
            $("#form1").attr('action',"{{url('admin/useradd')}}");
        });
        $(document).on('click','.luck-edit', function(){
            $('input[name=id]').val($(this).attr('data-id'));
            $('input[name=name]').val($(this).attr('data-name'));
            $('input[name=email]').val($(this).attr('data-email'));
            $("#form1").attr('action',"{{url('admin/useredit')}}");
        });

        $(document).on('click','.layui-btn', function(){
            var othis = $(this), method = othis.data('method');
            active[method] ? active[method].call(this, othis) : '';
        });
        var active={
            del:function(othis){
                var url=$(othis).attr('data-url');
                var id=$(othis).attr('data-id');
                var yesTest="{{trans('config.yes')}}";
                var noTest="{{trans('config.no')}}";
                layer.confirm("{{trans('config.btn_text_delete')}}", {icon: 3, title:"{{trans('config.message')}}"
                    ,btn: [yesTest,noTest]
                }, function(){
                    $.ajax({
                        url:url,
                        type:"post",
                        data:{"id":id,"_token":"{{csrf_token()}}"},
                        beforeSend:function(){
                            layer.load(1);
                        },
                        success:function(data){
                            if(data.status==200){
                                layer.msg("{{trans('config.submit_success')}}");
                                location.reload();
                            }else{
                                layer.msg("{{trans('config.submit_error')}}");
                            }
                        },
                        complete:function(){
                            layer.closeAll('loading');
                        },
                        error:function(){
                            layer.msg("{{trans('config.net_error')}}");
                        }
                    })
                }, function(){
                });
            }
        }
    })
</script>
@endsection